﻿@using DTcms.Common;
@{
    ViewBag.Title = "频道管理";
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">频道管理</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAdd" class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../channel/channel_edit?action=@DTEnums.ActionEnum.Add"><i class="iconfont icon-close1"></i> 新增</a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i> 删除</a>
                        </div>
                        <div class="menu-select">
                            <select class="select" lay-filter="btnSearch" name="ddlSiteId" url="/webapi/siteJson" selectValue="" promtion="所有站点"><option value="">所有站点</option></select>
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'name'}">名称</th>
                        <th lay-data="{field:'title'}">标题</th>
                        <th lay-data="{field:'siteTitle'}">所属站点</th>
                        <th lay-data="{field:'is_albums',templet:'#albums'}">相册</th>
                        <th lay-data="{field:'is_attach',templet:'#attach'}">附件</th>
                        <th lay-data="{field:'is_spec',templet:'#spec'}">规格</th>
                        <th lay-data="{field:'is_type',templet:'#type'}">方式</th>
                        <th lay-data="{field:'sort_id',edit: 'text'}">排序</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="albums">
    {{d.is_albums == 0?'<i class="simple text-success icon-close"></i>':'<i class="simple text-warning icon-check"></i>'}}
</script>
<script type="text/html" id="attach">
    {{d.is_attach == 0?'<i class="simple text-success icon-close"></i>':'<i class="simple text-warning icon-check"></i>'}}
</script>
<script type="text/html" id="spec">
    {{d.is_spec == 0?'<i class="simple text-success icon-close"></i>':'<i class="simple text-warning icon-check"></i>'}}
</script>
<script type="text/html" id="type">
    {{d.is_type == 0 ? '图片' : '列表'}}
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" data-dropdown="#dropUser{{d.LAY_INDEX}}" no-shade="true">更多 <i class="layui-icon layui-icon-drop" style="font-size: 12px;margin-right: 0;"></i></a>
    <ul class="dropdown-menu-nav dropdown-bottom-right layui-hide" id="dropUser{{d.LAY_INDEX}}">
        <div class="dropdown-anchor"></div>
        <li><a href="../channel/channel_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}"><i class="layui-icon layui-icon-edit"></i>修改</a></li>
        <li><a lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a></li>
        <li><a lay-event="print"><i class="layui-icon layui-icon-print"></i>打印</a></li>
    </ul>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table', 'dropdown', 'cascadeSelect', 'cmswh'], function () {
            var table = layui.table, form = layui.form, dropdown = layui.dropdown, cascadeSelect = layui.cascadeSelect, cmswh = layui.cmswh, $ = layui.jquery;
            cascadeSelect.init('ddlSiteId', false);

            cmswh.dataBind('ChannelList');
            //监听单元格编辑
            table.on('edit(ltable)', function (obj) {
                cmswh.request("ChannelFiledSave", "POST", { field: obj.field, value: obj.value, id: obj.data.id });
            });
            //监听工具条
            table.on('tool(ltable)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent === 'del') {
                    layer.msg('点击了下拉菜单删除');
                } else if (layEvent === 'print') {
                    layer.msg('点击了下拉菜单打印');
                }
                dropdown.hideAll();
            });
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                active[type] ? active[type].call(this) : '';
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('ChannelDelete', 'id', "如果该频道下还存在内容则无法删除，是否继续？");
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var siteId = $("select[name=ddlSiteId]").val();
                var postdata = { keywords: keywords, site_id: siteId };
                return postdata;
            }
        });
    </script>
}